<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>
  <body>
    <script>
      //检测昵称
      //汉字字母数字下划线组成
      function isNikename(nikename) {
        let reg = /^[\u4e00-\u9fa5a-z0-9_]{1,}$/;
        let result = reg.test(nikename);
        if (result) {
          console.log(nikename, "符合现有昵称规则");
        } else {
          console.log(nikename, "不符合现有昵称规则");
        }
      }
      isNikename("小行星");
      isNikename("小行星1");
      isNikename("小行星a2");
      isNikename("小行星_a3");
      isNikename("小行星-a4");
    </script>
  </body>
</html>
